package com.we.wecc.bg.api.controller;

import com.we.wecc.aw.db.model.Award;
import com.we.wecc.aw.db.model.AwardProduct;
import com.we.wecc.aw.mid.model.in.AwardIn;
import com.we.wecc.aw.mid.model.out.AwardOut;
import com.we.wecc.aw.mid.service.AwardService;
import com.we.wecc.bg.mid.model.in.AwardProductIn;
import com.we.wecc.bg.mid.model.out.ParticipationCountOut;
import com.we.wecc.bg.mid.model.out.WinOut;
import com.we.wecc.bg.mid.service.BackAwardService;
import com.x.share.api.controller.BaseController;
import com.x.share.db.model.Pagination;
import com.x.share.mid.exception.HelperException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(value = "云购后台接口")
@RestController
@RequestMapping("/back/aw")
public class BackAwardController extends BaseController {

    @Resource
    BackAwardService backAwardService;

    @Resource
    AwardService awardService;

    @ApiOperation(value = "获取奖品信息列表", notes= "获取奖品信息列表", response = AwardProduct.class)
    @RequestMapping(value = "/getAwardProductList", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getAwardProductList(
            @ApiParam(value = "当前页,默认第1页", defaultValue = "1") @RequestParam("pn") Integer pageNo,
            @ApiParam(value = "每页记录数", defaultValue = "10") @RequestParam("ps") Integer pageSize,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    )throws HelperException {
        Pagination<AwardProduct> page = backAwardService.getAwardProductList(pageNo, pageSize);
        return success(page);
    }

    @ApiOperation(value = "添加或修改奖品信息列表", notes= "添加或修改奖品信息列表", response = AwardProduct.class)
    @RequestMapping(value = "/saveAwardProduct", method = { RequestMethod.POST})
    public @ResponseBody Map<String, Object> saveAwardProduct(
            @RequestBody AwardProductIn in,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    ) throws HelperException {
        AwardProduct awardProduct = backAwardService.saveAwardProduct(in);
        return success(awardProduct);
    }

    @ApiOperation(value = "添加或修改云购活动", notes= "添加或修改云购活动", response = Award.class)
    @RequestMapping(value = "/saveAward", method = { RequestMethod.POST})
    public @ResponseBody Map<String, Object> saveAward(
            @RequestBody AwardIn in,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk
    ) throws HelperException {
        Award award = backAwardService.saveAward(in);
        return success(award);
    }

    @ApiOperation(value = "获取往期活动", notes= "获取往期活动", response = AwardOut.class)
    @RequestMapping(value = "/getAwardList", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getAwardList(
            @ApiParam(value = "当前期活动状态0未开始100预热200进行中300兑奖中400未完成500结束", defaultValue = "500") @RequestParam("awardStatus") Integer awardStatus,
            @ApiParam(value = "当前页,默认第1页", defaultValue = "1") @RequestParam("pn") Integer pageNo,
            @ApiParam(value = "每页记录数", defaultValue = "5") @RequestParam("ps") Integer pageSize,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
        Pagination<AwardOut> page = awardService.getAwardList(awardStatus, pageNo, pageSize);
        return success(page);
    }

    @ApiOperation(value = "根据id获取活动", notes= "根据id获取活动", response = AwardOut.class)
    @RequestMapping(value = "/getAward", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getAward(
            @ApiParam(value = "活动id") @RequestParam("awardId") Integer awardId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
        AwardOut out = awardService.getAward(awardId);
        return success(out);
    }

    @ApiOperation(value = "根据id获取参与情况", notes= "根据id获取参与情况", response = ParticipationCountOut.class)
    @RequestMapping(value = "/getParticipation", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getParticipation(
            @ApiParam(value = "活动id") @RequestParam("awardId") Integer awardId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
        ParticipationCountOut out = backAwardService.getParticipation(awardId);
        return success(out);
    }

    @ApiOperation(value = "获取本期中奖人", notes= "获取本期中奖人", response = WinOut.class)
    @RequestMapping(value = "/getCurrWinner", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getCurrWinner(
            @ApiParam(value = "活动id") @RequestParam("awardId") Integer awardId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
        WinOut out = backAwardService.getCurrWinner(awardId);
        return success(out);
    }

}
